// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   Win32SerialPort.java

package com.sun.comm;

import java.io.IOException;

// Referenced classes of package com.sun.comm:
//            Win32SerialPort

class NotificationThread extends Thread
{

    Win32SerialPort port;
    private static int EV_RXCHAR = 1;
    private static int EV_RXFLAG = 2;
    private static int EV_TXEMPTY = 4;
    private static int EV_CTS = 8;
    private static int EV_DSR = 16;
    private static int EV_RLSD = 32;
    private static int EV_BREAK = 64;
    private static int EV_ERR = 128;
    private static int EV_RING = 256;
    private static int CE_OVERRUN = 2;
    private static int CE_RXPARITY = 4;
    private static int CE_FRAME = 8;
    private static int CE_BREAK = 16;

    NotificationThread(String s, Win32SerialPort win32serialport)
    {
        super(s);
        port = win32serialport;
    }

    @Override
	public void run()
    {
        do
        {
            int i;
            do
            {
                if(port.closed || port.eventListener == null)
                {
                    port.notificationThread = null;
                    return;
                }
                i = port.waitForEvent();
                if(port.closed || port.eventListener == null)
                {
                    port.notificationThread = null;
                    return;
                }
                if((i & EV_CTS) == EV_CTS)
                    port.sendCTSevent();
                if((i & EV_DSR) == EV_DSR)
                    port.sendDSRevent();
                if((i & EV_RLSD) == EV_RLSD)
                    port.sendCDevent();
                if((i & EV_RING) == EV_RING)
                    port.sendRIevent();
                if((i & EV_BREAK) == EV_BREAK)
                    port.sendBIevent();
                if((i & EV_ERR) == EV_ERR)
                {
                    int j = i >> 16;
                    if((j & CE_OVERRUN) == CE_OVERRUN)
                        port.sendOEevent();
                    if((j & CE_RXPARITY) == CE_RXPARITY)
                        port.sendPEevent();
                    if((j & CE_FRAME) == CE_FRAME)
                        port.sendFEevent();
                }
                if((i & EV_TXEMPTY) == EV_TXEMPTY)
                    port.sendOutputEmptyEvent();
                if((i & EV_RXCHAR) == EV_RXCHAR)
                {
                    synchronized(port.readSignal)
                    {
                        port.readSignal.notifyAll();
                    }
                    try
                    {
                        if(port.available() > 0)
                            port.sendDataAvailEvent();
                    }
                    catch(IOException _ex) { }
                }
            } while((i & EV_RXFLAG) != EV_RXFLAG);
            port.framingByteReceived = true;
            synchronized(port.readSignal)
            {
                port.readSignal.notifyAll();
            }
        } while(true);
    }

}
